<?php
/**
 * Created by PhpStorm.
 * User: xuyiping
 * Date: 2019/1/10
 * Time: 22:29
 */

namespace app\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Model\UserModel;
use Illuminate\Http\Request;

class YLoginController extends Controller {

    public function login(Request $request){

        $user_name = $request->input('user_name');
        $password  = md5($request->input('password'));

    }

    public function register(Request $request){
        $user_name = $request->input('user_name');
        $password  = md5($request->input('password'));
        $use_password  = md5($request->input('use_password'));
        $email = $request->input('email');
        $nickname = $request->input('nickname');

        if(!isset($user_name) || empty($user_name)){
            return json_encode(['code'=>400,'message'=>'用户名不能为空','data'=>[]]);
        }
        if(!isset($password) || empty($password)){
            return json_encode(['code'=>400,'message'=>'用户密码不能为空','data'=>[]]);
        }

        if(!isset($email) || empty($email)){
            return json_encode(['code'=>400,'message'=>'用户邮箱不能为空','data'=>[]]);
        }

        if(!isset($nickname) || empty($nickname)){
            return json_encode(['code'=>400,'message'=>'用户昵称不能为空','data'=>[]]);
        }

        if(!isset($use_password) || empty($use_password)){
            return json_encode(['code'=>400,'message'=>'用户确认密码不能为空','data'=>[]]);
        }

        if($password !=$use_password ){
            return json_encode(['code'=>400,'message'=>'确认密码错误','data'=>[]]);
        }


        $user_id = UserModel::insertGetId([
            'user_name'=> $user_name,
            'email'=> $email,
            'password'=> $password,
            'nickname'=> $nickname ? $nickname : '',
        ]);

        return json_encode(['code'=>200,'message'=>'ok','data'=>['user_id'=>$user_id]]);
    }

}